<template>
	<view class="count">
		<view class="rop">
			<image src="/static/login/log.png" class="logImg" mode=""></image>
			<image src="/static/login/title.png" class="logTit" mode=""></image>
		</view>
		<!-- 下面的按钮 -->
		<button open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber" class="btn f f-a-c f-j-c" :plain="true">
			<!-- <image src="/static/login/wechat.png" class="wechatImg m-r-10" mode=""></image> -->
			<view class="">
				手机号授权快捷登录
			</view>
		</button>
		<!-- 下面的同意服务 -->
		<view class="botService f f-a-c f-j-c">
			<image src="/static/login/gou.png" v-if="index==1" @click="tongyi(2)" class="img m-r-10" mode=""></image>
			<image src="/static/login/weigou.png" v-else @click="tongyi(1)" class="img m-r-10" mode=""></image>
			<view class="agree">
				我已阅读并同意 <text @click="user_agree">《服务协议》</text> 和 <text @click="privacy_policy">《隐私政策》</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: 2
			}
		},
		methods: {
			tongyi(num) {
				this.index = num
			},
			// 用户协议
			user_agree() {
				uni.navigateTo({
					url: '/pageC/detils?name=user_agree'
				})
			},
			// 隐私政策
			privacy_policy() {
				uni.navigateTo({
					url: '/pageC/detils?name=privacy_policy'
				})
			},
			decryptPhoneNumber(e) {
				if (this.index != 1) {
					return this.$msg('请勾选下方协议！')
				}
				uni.login({
					provider: 'weixin', //使用微信登录
					success: async (res) => {

						let n = await this.$api.Login({
							code: res.code,
							// code: 'test',
							shop_id: uni.getStorageSync('shop_id') || '',
							parent_id: uni.getStorageSync('code') || ''
						})
						console.log(n, '123');
						uni.setStorageSync('token', n.data.token)
						// 绑定手机号
						let m = await this.$api.LoginPhone({
							code: e.target.code
						})
						if (!m.status) return this.$msg(m.message)
						// if (m.code == 2001) this.$msg(m.message)
						// 这个是用户信息
						let userinfo = await this.$api.Profile()
						// userinfo.data.avatar = ''
						uni.setStorageSync('userinfo', userinfo.data)
						if (m.status) {
							this.$msg('登陆成功!')
							uni.removeStorageSync('code')
							uni.removeStorageSync('shop_id')
							setTimeout(() => {
								if (userinfo.data && userinfo.data.avatar) {
									// 跳转到引导页
									uni.navigateTo({
										url: '/pageA/Introduction'
									})
								} else {
									uni.navigateTo({
										url: '/pageLogin/settingAvatar'
									})
								}
								// return

							}, 1000)
						}
						// 存储token
					}
				});
			}
		}
	}
</script>
<style>
	page {
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.botService {
		position: fixed;
		bottom: 200rpx;
		width: 100%;
		left: 0;

		.agree {
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 500;
			color: #999999;

			text {
				color: #009D85;
			}
		}

		.img {
			width: 28rpx;
			height: 28rpx;
		}
	}

	.btn {
		width: 90%;
		height: 84rpx;
		line-height: 84rpx;
		background: #009d85;
		border-radius: 42rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: 700;
		color: #ffffff;
		margin: 0 auto;
		margin-top: 150rpx;

		.wechatImg {
			width: 44rpx;
			height: 36rpx;
		}
	}

	button {
		padding: 0;
		margin: 0;
		border: none;
	}

	.logImg {
		width: 178rpx;
		height: 158rpx;
		margin-left: 50%;
		transform: translateX(-50%);
	}

	.logTit {
		width: 306rpx;
		height: 42rpx;
		margin-left: 50%;
		margin-top: 20rpx;
		transform: translateX(-50%);
	}

	.rop {
		margin-top: 25%;
	}
</style>